package com.kaizeli.website.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BusinessException extends RuntimeException {

    private final String code;
    private final String message;

    public BusinessException(BusinessErrorEnum errorEnum, Object... params) {
        this.code = errorEnum.getCode();
        this.message = formatMessage(errorEnum.getMessage(), params);
    }

    private String formatMessage(String template, Object... params) {
        if (params == null || params.length == 0) {
            return template;
        }
        return String.format(template, params);
    }
}